package nero.yncc.com.createart.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.util.ArrayList;

import nero.yncc.com.createart.R;
import nero.yncc.com.createart.activity.ActivityGoodDetail;
import nero.yncc.com.createart.bean.TejiaBean;
import nero.yncc.com.createart.utils.ImageUtils;
import nero.yncc.com.createart.utils.TextUtil;

/**
 * Created by nero on 17-6-21.
 */

public class AdapterIndexTejia extends BaseAdapter {

    Context context;
    ArrayList<TejiaBean> arrayList;

    public AdapterIndexTejia(Context context, ArrayList<TejiaBean> arrayList) {
        this.context = context;
        this.arrayList = arrayList;
    }

    @Override
    public int getCount() {
        return arrayList.size();
    }

    @Override
    public Object getItem(int i) {
        return i;
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        Holder holder;
        if (view == null) {
            view = LinearLayout.inflate(context, R.layout.adapter_index_hot, null);
            holder = new Holder(view);
            view.setTag(holder);
        } else {
            holder = (Holder) view.getTag();
        }
        final TejiaBean godBean = arrayList.get(i);

        holder.tv_content.setText(TextUtil.getText(godBean.getDescription(), "暂无简介"));
        holder.tv_hadsale.setText(TextUtil.getText("已售: " + godBean.getBuy_num(), "已售: 0"));
        holder.tv_money.setText("￥" + godBean.getPrice());
        holder.tv_title.setText(TextUtil.getText(godBean.getGoods_name(), "暂无名字"));
        ImageUtils.BindImage(context, holder.iv_image, godBean.getThumb(),1);

       view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(context,ActivityGoodDetail.class);
                intent.putExtra("id",godBean.getGoods_id());
                context.startActivity(intent);
            }
        });
        return view;
    }

    class Holder extends RecyclerView.ViewHolder {
        public Holder(View root) {
            super(root);
            tv_title = root.findViewById(R.id.tv_title);
            tv_content = root.findViewById(R.id.tv_content);
            tv_money = root.findViewById(R.id.tv_money);
            tv_hadsale = root.findViewById(R.id.tv_hadsale);
            iv_image = root.findViewById(R.id.iv_image);
        }

        final TextView tv_title, tv_content, tv_money, tv_hadsale;
        final ImageView iv_image;
    }
}
